﻿using com.iot.core.boot;
using com.iot.core.exception;
using CSRedis;

namespace com.iot.ht.Controllers.htsoft.service
{
    public class AppCheckRedis : AppCheck
    {
        string connectionString = "";
        string key = "";
        CSRedisClient redis = null;
         

        public override async Task<MyApiResult> Check()
        {
            var r = new MyApiResult();
            try
            {
                if (connectionString == "")
                {
                    connectionString = HtSoftApp.CkArg1;
                    key = "NetSvr2023" + HtSoftApp.Id.ToString();
                    if (!string.IsNullOrEmpty(HtSoftApp.CkArg2))
                    {
                        key = HtSoftApp.CkArg2;
                    }
                }
                if(redis==null)
                {
                    redis = new CSRedisClient(connectionString);
                }
                redis.Set(key, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                r.Msg = await redis.GetAsync(key);
            }
            catch (Exception ex)
            {
                r.Code = 1;
                r.Msg = MyExceptionUtil.GetExMsg(ex);


            }
            return r;
        }
    }
}
